package top.chengdongqing.mishop.product.review

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import top.chengdongqing.mishop.common.pageable.Page1
import top.chengdongqing.mishop.common.pageable.PageRequest1
import top.chengdongqing.mishop.product.review.vo.ProductReviewStatisticsVO
import top.chengdongqing.mishop.product.review.vo.ProductReviewVO

@RestController
@RequestMapping("/products/{productId}/reviews")
class ProductReviewController(private val reviewService: ProductReviewService) {

    @GetMapping("/statistics")
    fun statistics(@PathVariable productId: Int): ProductReviewStatisticsVO {
        return reviewService.statistics(productId)
    }

    @GetMapping
    fun findAllByPage(
        @PathVariable productId: Int,
        rating: Int?,
        withPhotosOnly: Boolean?,
        pageRequest: PageRequest1
    ): Page1<ProductReviewVO> {
        return reviewService.findAllByPage(productId, rating, withPhotosOnly, pageRequest.get())
    }
}